//
//  FirstLunchViewController.m
//  SuoSiApp
//
//  Created by zhang on 16/4/7.
//  Copyright © 2016年 Ym. All rights reserved.
//

#import "ViewController.h"
#import "FirstLunchViewController.h"

@interface FirstLunchViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) UIPageControl *pageControl;
//跳转button
@property (nonatomic, strong) UIButton *buttonGo;

@end

@implementation FirstLunchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = BSGreen;
//    self.navigationController.navigationBar.alpha = 1;
    

    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self addScrollView];
    [self addPageControlView];

}

- (void)addScrollView{

//    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScrenWidth, kScreenHeight)];
    self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    self.scrollView.bounces = NO;
    self.scrollView.contentSize = CGSizeMake(kScrenWidth * Guide_numbers, kScrenHeight -20);
    self.scrollView.backgroundColor  = BSWhite;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.pagingEnabled  =  YES;
    self.scrollView.delegate = self;
    [self.view addSubview: _scrollView];
    
    
//    设置引导页的内容
    for (int i = 0; i < Guide_numbers; i++) {
        NSString *str = [NSString stringWithFormat:@"appGuide_0%d.jpg",i + 1];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * kScrenWidth, 0, kScrenWidth, kScrenHeight)];
        imageView.image = [UIImage imageNamed:str];
        [self.scrollView addSubview:imageView];
        if (i == Guide_numbers - 1) {
            self.buttonGo = BSButton;
            _buttonGo.frame = CGRectMake(kScrenWidth * i + kScrenWidth / 3, kScrenHeight * 3 / 4, kScrenWidth/3, kScrenWidth/6);
            [_buttonGo setBackgroundImage:[UIImage imageNamed:@"appGuide_05.png"] forState:(UIControlStateNormal)];
            [_buttonGo addTarget:self action:@selector(buttonClict) forControlEvents:(UIControlEventTouchUpInside)];
            [_scrollView addSubview:_buttonGo];
        }
        
        
    }
    

    
}

- (void)addPageControlView{

    self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(kScrenWidth/3,  self.buttonGo.bottom + kMartin25, kScrenWidth/3, kMartin30)];
//    self.pageControl.backgroundColor = BSBlack;
    self.pageControl.numberOfPages = Guide_numbers;
    self.pageControl.currentPage = 0;
    self.pageControl.tintColor = BSWhite;
    self.pageControl.currentPageIndicatorTintColor = BSGreen;
    
    
    [self.view addSubview:_pageControl];

}
//图片停止减速时  触发
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //通过偏移量得 x 的坐标来关联currentPage

    CGFloat x = scrollView.contentOffset.x;
    _pageControl.currentPage = x/kScrenWidth;
    
    
}



- (void)buttonClict{
    NSLog(@"进入主界面");
    [_buttonGo setBackgroundImage:[UIImage imageNamed:@"appGuide_05s.png"] forState:(UIControlStateNormal)];
    ViewController *VC = [[ViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
